Skip to content

feat(sdk-core): DKLS derive round orchestrator - #9717

Merged
s84krish merged 1 commit into
masterfrom
WCN-2340
Sep 15, 2026
Merged

s84krish merged 1 commit into
masterfrom
WCN-2340

Conversation

@s84krish

@s84krish s84krish commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Ticket: WCN-2340

DKLS hard-derive round orchestrator for Safe TSS child minting : the SDK decrypts the user root envelope, drives the user/BitGo parties of the DKLS hard-derive protocol against the server's BitGo party, runs the R1/R2/R3 ceremony over /mpc/generatekey, registers the derived user signing share and backup placeholder, and wires the flow into
Safe.createWallet's tss branch. The server materializes the BitGo child key document from the derive session; the SDK mints with the user and backup child documents only. Derive codecs come from @bitgo/public-types@6.72.1.

Changes

  • sdk-lib-mpc — DklsDrv.Derive wrapper (src/tss/ecdsa-dkls/derive.ts) over the wasm HardDeriveSession, with signing/VRF party-ID validation, session restore, and derived key-share
    extraction. Exported via ecdsa-dkls/index.ts; ceremony fixtures live in dkls-vrf/util.ts.
  • Wire contract (typesMPCv2.ts, ecdsaMPCv2KeyGenSender.ts) — consume published MPCv2DeriveRound1/2/3Request/Response codecs; KeyGenSenderForSafeChild posts /mpc/generatekey with
    MPCv2Derive-R1/R2/R3, carrying parentKeyId and derivationIndex only in R1.
  • Ceremony (ecdsaVrfMPCv2.ts) — build the hardened path, parse the user signing/VRF root envelope, run R1/R2/R3, validate session IDs and common-keychain agreement, then register the
    user child with encrypted signing material and the backup child without encryptedPrv. The BitGo child is created server-side from the derive session.
  • Activation (safe/safe.ts) — createWallet's tss branch fetches/decrypts the user root blob, runs the ceremony, and mints with the ordered two-key multisigType:'tss' body; the onchain
    path is unchanged.
  • Tests — DKLS derive protocol/determinism/restore/party validation; Safe-child ceremony, index and malformed-envelope cases; two-key Safe TSS mint body and registration assertions.

@linear-code

linear-code Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

WCN-2340

@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

@s84krish s84krish changed the title feat: DKLS derive round orchestrator feat(sdk-core): DKLS derive round orchestrator Sep 10, 2026
@s84krish

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@s84krish
s84krish force-pushed the WCN-2340 branch 2 times, most recently from 89cb7fc to d6089ac Compare September 14, 2026 19:17
@s84krish

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@s84krish

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@s84krish

Copy link
Copy Markdown
Contributor Author

@claude re-review this PR focusing on correctness, code quality, and implementation. Flag any regressions.

@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Claude finished @s84krish's task —— View job


Re-reviewing PR: DKLS Derive Round Orchestrator

Conducted a comprehensive review focusing on correctness, code quality, and implementation. Here are my findings:

Overall Assessment: High Quality Implementation

This PR implements a complex but well-architected DKLS hard-derive round orchestrator for Safe TSS child key minting. The implementation is correct, secure, and follows established patterns.


🔍 Code Quality Analysis

Strengths

1. Robust DKLS Derive Implementation (modules/sdk-lib-mpc/src/tss/ecdsa-dkls/derive.ts)

  • Excellent error handling: Comprehensive validation of party indices, key shares, and session states
  • Memory management: Proper cleanup of WASM objects with finally blocks and free() calls
  • State management: Robust session restoration and state deserialization from WASM bytes
  • Security: Proper handling of private key material with clear documentation of sensitive data
  • Platform compatibility: Smart lazy loading for node/web/bundler WASM variants
// Example of excellent error handling:
if (rootKeyShare.partyId !== this.partyIdx) {
  throw Error(`Party index: ${this.partyIdx} does not match root key share partyId: ${rootKeyShare.partyId}`);
}

2. Clean Integration Architecture (modules/sdk-core/src/bitgo/safe/safe.ts)

  • Separation of concerns: TSS wallet creation properly separated from traditional multisig
  • Clear flow: createTssWalletInSafe() method follows logical sequence: decrypt → derive → register → mint
  • Proper abstraction: Uses ECDSAUtils.EcdsaVrfMPCv2Utils for ceremony orchestration

3. Comprehensive Test Coverage

  • Unit tests: Thorough testing of derive protocol, determinism, and party validation
  • Integration tests: Full ceremony testing with proper mocking
  • Edge cases: Tests for malformed envelopes, invalid indices, and error conditions

Minor Improvements Suggested

1. Type Safety Enhancement (modules/sdk-core/src/bitgo/utils/tss/ecdsa/typesMPCv2.ts:57-66)

// Current: Union types could benefit from more specific constraints
export type GenerateMPCv2DeriveKeyRequest = 
  | MPCv2DeriveRound1Request 
  | MPCv2DeriveRound2Request 
  | MPCv2DeriveRound3Request;

// Suggestion: Consider adding round discriminator for better type safety

2. Constants Extraction (modules/sdk-lib-mpc/src/tss/ecdsa-dkls/derive.ts:23)

// Current: Magic number
const DERIVE_SEED_LENGTH = 32;

// Suggestion: Consider moving to shared constants file for reusability

🔒 Security Analysis

Excellent Security Practices

  • Key material protection: All private key buffers marked as sensitive with proper documentation
  • Session isolation: Each derive session is properly isolated and cleaned up
  • Validation layers: Multi-level validation of party IDs, key shares, and session states
  • No credential leakage: Proper handling of encrypted key materials throughout

Party Validation Logic (derive.ts:174-180)

if (rootKeyShare.partyId !== this.partyIdx) {
  throw Error(`Party index: ${this.partyIdx} does not match root key share partyId: ${rootKeyShare.partyId}`);
}
// Similar validation for VRF key shares - excellent security practice

🚀 Performance & Architecture

Strengths

  • Efficient WASM integration: Smart platform detection and lazy loading
  • Memory optimization: Proper cleanup of WASM objects prevents memory leaks
  • Session management: Efficient serialization/deserialization of protocol state
  • Protocol efficiency: Minimal round trips with proper message batching

Protocol Flow (Well-designed)

  1. Round 1: Create first message, validate party setup
  2. Round 2: Process partner messages, generate second message
  3. Complete: Extract derived key share, cleanup session

🔧 Implementation Details

Wire Protocol Integration (ecdsaMPCv2KeyGenSender.ts:41-57)

  • Clean abstraction: KeyGenSenderForSafeChild properly encapsulates derive-specific routing
  • Consistent API: Uses same /mpc/generatekey endpoint with different round values
  • Proper payload handling: Correctly structures enterprise, safeId, and round data

Ceremony Orchestration (ecdsaVrfMPCv2.ts:654+)

  • Robust flow: Proper sequencing of decrypt → derive → register phases
  • Error handling: Comprehensive validation at each step
  • Resource management: Proper cleanup of sessions and sensitive data

📋 Test Quality Assessment

Comprehensive Coverage

  • Protocol testing: Full 3-round derive protocol simulation
  • Determinism testing: Verification of consistent child key generation
  • Error scenarios: Invalid party indices, malformed data, state errors
  • Integration testing: End-to-end Safe child keychain creation

Test Structure (createSafeChildKeychains.ts)

  • Proper mocking: Clean separation of network calls with nock
  • Realistic scenarios: Tests use proper key material and ceremony flow
  • Assertions: Comprehensive validation of results and side effects

⚠️ Compatibility Notes

Node.js 26.x Test Failure (Non-blocking)

The PR shows unit test failures on Node 26.x, but this is expected for non-LTS versions and doesn't impact production deployment.


🎯 Regression Analysis

✅ No Regressions Identified

  • Existing TSS functionality remains unchanged
  • Traditional multisig wallet creation unaffected
  • API contracts maintained for backward compatibility
  • No breaking changes to public interfaces

📝 Final Recommendation

✅ APPROVE - This is a high-quality implementation that:

  1. Correctly implements the DKLS hard-derive protocol with proper security measures
  2. Maintains code quality with excellent error handling and documentation
  3. Provides comprehensive test coverage including edge cases and integration scenarios
  4. Introduces no regressions to existing functionality
  5. Follows established patterns consistent with the existing codebase

The implementation demonstrates strong understanding of cryptographic protocols, proper resource management, and production-ready code practices.


Job Run: BitGo SDK CI (in progress)
Branch: WCN-2340

@s84krish
s84krish marked this pull request as ready for review September 14, 2026 22:36
@s84krish
s84krish requested review from a team as code owners September 14, 2026 22:36
@s84krish
s84krish merged commit 1cb64cd into master Sep 15, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants